--exec sp_toshiba_wip_info_report 0, '0','0', '0' 

ALTER      proc sp_toshiba_wip_info_report

@step_id int,
@process_step_type varchar(15),
@asOfDate varchar(20),
@default_prompt varchar(20)
as
	
	--Added by murali 25/05/2004
	declare @date_time datetime
	declare @start_date datetime
	declare @end_date datetime
	declare @temp_varchar varchar(20)

		declare @results Table(Toshiba_id bigint,Manfacturing_Part_Number varchar(50) , Customer_Part_Number varchar(50), ProcessStep_Id bigint,
		Lot_Id  bigint,State varchar(30) ,Start int,Gate  int,Pimplantation int,Contact int,One_Via int,One_AL int,
		Two_Via int,Two_Al int,Three_Via int,Three_Al int,Four_Via int,Four_Al int,Five_Via int,Five_Al int,Six_Via int,
		Six_Al int,Passivation int,Wafer_Sort int,Lapping int,Dicing int,Test int,Packing int,Qc int,Bump int,
		Dieattach int,Mold int,Trim_And_Form int,Storage_Works int,Storage_Other int,Timestamp datetime)


	     begin
		
		if @asOfDate <> '0'
		begin
			--select  @date_time = max(Timestamp) from Toshiba_Wip_Details  
			set @date_time = @asOfDate

		end
		else if @asOfDate = '0'
		begin	
			set @date_time = convert(varchar, CURRENT_TIMESTAMP, 101)
		end

		set @temp_varchar = convert(varchar, @date_time, 101)+' 12:00AM'
		set @start_date = convert(datetime, @temp_varchar)
		set @temp_varchar = null
		set @temp_varchar = convert(varchar, @date_time, 101)+' 11:59PM' 
		set @end_date = convert(datetime, @temp_varchar)

		if @date_time is not null
		begin
   	  		if @date_time between @start_date and @end_Date
	   		begin
				insert into @results select * from Toshiba_Wip_Details
				select * from @results where  Timestamp between @start_date and @end_Date
	   		end
		end
		else 
		begin
			select * from @results
		end

     end